/*
xp_time.h
offer system set basetime and get time api
designed by lunanting

-------------------------------
2020-05-10 17:00:02
create file
-------------------------------

*/
#include "base_type.h"
#ifndef __XP_TIME_H
#define __XP_TIME_H

/*************************data type define**************************/
/*
 * RTC time
 */
typedef struct {
    uint8_t sec;     /**< DEC format:value range from 0 to 59, BCD format:value range from 0x00 to 0x59 */
    uint8_t min;     /**< DEC format:value range from 0 to 59, BCD format:value range from 0x00 to 0x59 */
    uint8_t hr;      /**< DEC format:value range from 0 to 23, BCD format:value range from 0x00 to 0x23 */
    uint8_t weekday; /**< DEC format:value range from 1 to  7, BCD format:value range from 0x01 to 0x07 */
    uint8_t date;    /**< DEC format:value range from 1 to 31, BCD format:value range from 0x01 to 0x31 */
    uint8_t month;   /**< DEC format:value range from 1 to 12, BCD format:value range from 0x01 to 0x12 */
    uint16_t year;   /**< DEC format:value range from 0 to 9999, BCD format:value range from 0x0000 to 0x9999 */
} RTC_time;



/********************************function extern *************************/
extern void xp_time_set_unix(u64 time); //set base time
extern void xp_time_set_ms(u64 timems); //set base time ms
extern u64 xp_time_get_unix(void);  //get unix time
extern u64 xp_time_get_ms(void);    //get ms time
extern char *xp_time_get_string(void);  //get DATE string
extern char *xp_date_string_get(void);  //get date string
extern char *xp_date_hour_string_get(void); //get date-hour string
extern char *xp_timeMS_string_get(void);    //get time string with miro sec ms
extern u64 xp_time_get_diff_ms(u64 start_time);
extern char* xp_msTostring(u64 ms);  //ms to days format string

extern int xp_rtc_init(void);   //init external rtc 
extern int xp_rtc_set(RTC_time *time);  //set external rtc time
extern RTC_time *xp_rtc_get(void);   //get external rtc time
extern int xp_rtc_set_with_unix(int unix);  //set external rtc with unix time sec

#endif
//end of the file
